import datetime
import math
import os
import time
import sys

# 将工程目录加入包扫描
currPath = os.path.abspath(os.path.dirname(__file__))
srcPath = os.path.split(currPath)[0]
rootPath = os.path.split(srcPath)[0]
projectPath = os.path.split(rootPath)[0]
sys.path.append(projectPath)

from src.db.CcxDataCenterDb import CcxDataCenter
from src.db.FCDB import FCDB
from src.db.LocalDb import LocalDb
from src.tasks.credit.SyncReportDataInfo import SyncReportDataInfo
from src.utils.CommonUtils import cleanScreen

from src.utils.LogUtils import Logger


# 主函数
def main():
    logger = Logger()
    localDb = LocalDb(logSql=False, autocommit=True)
    dataCenterDb = CcxDataCenter(logSql=False, autocommit=True)
    fcdb = FCDB(logSql=False, autocommit=True)

    cleanScreen()
    t = time.perf_counter()

    logger.info("========报告信息 开始 ========")
    # 更新主体基础信息
    sync = SyncReportDataInfo(logger=logger, localDb=localDb, dataCenterDb=dataCenterDb, fcdb=fcdb)
    sync.sync()

    cast = (time.perf_counter() - t)
    m = math.floor(cast / 60)
    s = cast - m * 60
    logger.info('总耗时: %d分%.3f秒' % (m, s))
    logger.info("========报告信息 结束 ========")


# 程序入口 报告研究 credit_research_report
if __name__ == "__main__":
    main()
